package com.gec.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gec.domain.User;
import com.gec.service.UserService;
import com.gec.service.impl.UserServiceImpl;

@WebServlet("/addUser.action")
public class AddUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public AddUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置字符编码 
		//接收id,name,password,sex
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		String sex = request.getParameter("sex");
		
		UserService service = new UserServiceImpl();
		service.save(new User(name,password,sex));
		
		//跳转到主页
		RequestDispatcher dispatcher = request.getRequestDispatcher("usercontrol.action");
		dispatcher.forward(request, response);
		//客户端跳转
		//response.sendRedirect("usercontrol");
	}

}
